﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：预算管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'pbdbudgets/delete/' + keyValue + '?access_token=' + config.getToken().access_token, {keyValue: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });

            // 从excel导入
            $('#lr_import').on('click', function () {
                learun.layerForm({
                    id: 'UploadifyForm',
                    title: '上传文件',
                    url: config.webportal_server + 'pages/datahouse/pz/uploadifyForm.html?access_token=' + config.getToken().access_token,
                    width: 600,
                    height: 400,
                    callBack: function (id) {
                        return top[id].acceptClick(function (datas) {
                            if (datas) {
                                refreshGirdData();
                            }
                        });
                    }
                });
            });
            // 数据导出
            $('#lr_export').on('click', function () {
                location.href = config.base_server() + 'pbdbudgets/exportExcel?access_token=' + config.getToken().access_token;
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'impkjpzs/list?access_token=' + config.getToken().access_token,
                headData: [
                    {
                        label: "凭证日期", name: "pzrq", width: 100, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd');
                        }
                    },
                    {label: '凭证号', name: 'pzh', width: 110, align: 'center'},
                    {label: '摘要', name: 'zy', width: 200, align: 'left'},
                    {
                        label: '借方金额', name: 'j', width: 100, align: 'center',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: '贷方金额', name: 'd', width: 100, align: 'center',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {label: '票据号', name: 'pjh', width: 100, align: 'center'},
                    {label: '会计科目', name: 'kjkm', width: 180, align: 'left'},
                    {label: '对方科目', name: 'dfkm', width: 200, align: 'center'},
                    {label: '部门支出经济分类', name: 'bmzcjjfl', width: 100, align: 'left'},
                    {label: '财政拨款种类', name: 'czbkzl', width: 100, align: 'left'},
                    {label: '财政指标', name: 'czzb', width: 100, align: 'left'},
                    {label: '执行款案号', name: 'ah', width: 100, align: 'left'},
                    {label: '费用经济性质', name: 'fyjjxz', width: 100, align: 'left'},
                    {label: '民事案件暂存款', name: 'msajzck', width: 100, align: 'left'},
                    {label: '随案移送赃款(暂存)', name: 'sayszk', width: 100, align: 'left'},
                    {label: '往来单位', name: 'wldw', width: 100, align: 'left'},
                    {label: '项目', name: 'xm', width: 100, align: 'left'},
                    {label: '刑事暂存款', name: 'xszck', width: 100, align: 'left'},
                    {label: '预算项目', name: 'ysxm', width: 100, align: 'left'},
                    {label: '支出功能分类科目', name: 'zcgnflkm', width: 100, align: 'left'},
                    {label: '资产分类', name: 'zcfl', width: 100, align: 'left'},
                    {label: '支付方式', name: 'zffs', width: 100, align: 'left'}
                ],
                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


